$(function () {
	
	
	/*-----------------price-slider--------------*/
	var def_price_min=parseInt($("#price_from").val());
	var def_price_max=parseInt($("#price_to").val());
	$("#slider_price").slider({
		range: true,
		step: 100, 
		min:def_price_min,
		max:def_price_max,
		values:[def_price_min,def_price_max],
		create: function(event, ui) {
			$(this).find("a:first").addClass('first');
		},
		slide: function( event, ui ) {
			$("#price_from").val(ui.values[0]);
			$("#price_to").val(ui.values[1]);
		}
	});
	$("#price_from").attr('autocomplete','off');
	$("#price_from").spinbox({
		  min: def_price_min,   
		  max: def_price_max,
		  step: 100,
		  bigStep:1000,
		  buttonWidth:1,
		  keys			: [ /[0-9]/,9,13,8,46,33,34,35,36,37,38,39,40,188,190,96,97,98,99,100,101,102,103,104,105 ]
		}).keyup(
				function(){
						$(this).val(Number($(this).val()));
				}		
		).change(function(){
			var value=parseInt($("#price_from").val());
			$("#slider_price").slider( "values" , 0 , value );
		}).unbind('mousemove.spinbox').unbind('mouseout.spinbox').unbind('mousedown.spinbox').unbind('mouseup.spinbox');
	
	$("#price_to").attr('autocomplete','off');
	$("#price_to").spinbox({
		  min: def_price_min,   
		  max: def_price_max,
		  step: 100,
		  bigStep:1000,
		  buttonWidth:1,
		  keys			: [ /[0-9]/,9,13,8,46,33,34,35,36,37,38,39,40,188,190,96,97,98,99,100,101,102,103,104,105 ]
		}).keyup(
				function(){
						$(this).val(Number($(this).val()));
				}		
		).change(function(){
			var value=parseInt($("#price_to").val());
			$("#slider_price").slider( "values" , 1 , value );
		}).unbind('mousemove.spinbox').unbind('mouseout.spinbox').unbind('mousedown.spinbox').unbind('mouseup.spinbox');	
	
	
	
	
	/*----------------------------------------length_slider--------------------------------------------------------------*/
	var def_length_min=parseInt($("#length_from").val());
	var def_length_max=parseInt($("#length_to").val());
	$("#slider_length").slider({
		range: true,
		step: 100,
		min:def_length_min,
		max:def_length_max,
		values:[def_length_min,def_length_max],
		create: function(event, ui) {
			$(this).find("a:first").addClass('first');
		},
		slide: function( event, ui ) {
			$("#length_from").val(ui.values[0]);
			$("#length_to").val(ui.values[1]);
		}
	});
	$("#length_from").attr('autocomplete','off');
	$("#length_from").spinbox({
		  min: def_length_min,   
		  max: def_length_max,
		  step: 10,
		  bigStep:50,
		  buttonWidth:1,
		  keys			: [ /[0-9]/,9,13,8,46,33,34,35,36,37,38,39,40,188,190,96,97,98,99,100,101,102,103,104,105 ]
		}).keyup(
				function(){
						$(this).val(Number($(this).val()));
				}		
		).change(function(){
			var value=parseInt($("#length_from").val());
			$("#slider_length").slider( "values" , 0 , value );
		}).unbind('mousemove.spinbox').unbind('mouseout.spinbox').unbind('mousedown.spinbox').unbind('mouseup.spinbox');
	
	$("#length_to").attr('autocomplete','off');
	$("#length_to").spinbox({
		  min: def_length_min,   
		  max: def_length_max,
		  step: 100,
		  bigStep:200,
		  buttonWidth:1,
		  keys			: [ /[0-9]/,9,13,8,46,33,34,35,36,37,38,39,40,188,190,96,97,98,99,100,101,102,103,104,105 ]
		}).keyup(
				function(){
						$(this).val(Number($(this).val()));
				}		
		).change(function(){
			var value=parseInt($("#length_to").val());
			$("#slider_length").slider( "values" , 1 , value );
		}).unbind('mousemove.spinbox').unbind('mouseout.spinbox').unbind('mousedown.spinbox').unbind('mouseup.spinbox');
	
	/*----------------------------------------width_slider--------------------------------------------------------------*/
	var def_width_min=parseInt($("#width_from").val());
	var def_width_max=parseInt($("#width_to").val());
	$("#slider_width").slider({
		range: true,
		step: 50,
		min:def_width_min,
		max:def_width_max,
		values:[def_width_min,def_width_max],
		create: function(event, ui) {
			$(this).find("a:first").addClass('first');
		},
		slide: function( event, ui ) {
			$("#width_from").val(ui.values[0]);
			$("#width_to").val(ui.values[1]);
		}
	});
	$("#width_from").attr('autocomplete','off');
	$("#width_from").spinbox({
		  min: def_width_min,   
		  max: def_width_max,
		  step: 50,
		  bigStep:100,
		  buttonWidth:1,
		  keys			: [ /[0-9]/,9,13,8,46,33,34,35,36,37,38,39,40,188,190,96,97,98,99,100,101,102,103,104,105 ]
		}).keyup(
				function(){
						$(this).val(Number($(this).val()));
				}		
		).change(function(){
			var value=parseInt($("#width_from").val());
			$("#slider_width").slider( "values" , 0 , value );
		}).unbind('mousemove.spinbox').unbind('mouseout.spinbox').unbind('mousedown.spinbox').unbind('mouseup.spinbox');
	
	$("#width_to").attr('autocomplete','off');
	$("#width_to").spinbox({
		  min: def_width_min,   
		  max: def_width_max,
		  step: 50,
		  bigStep:100,
		  buttonWidth:1,
		  keys: [ /[0-9]/,9,13,8,46,33,34,35,36,37,38,39,40,188,190,96,97,98,99,100,101,102,103,104,105 ]
		}).keyup(
				function(){
						$(this).val(Number($(this).val()));
				}		
		).change(function(){
			var value=parseInt($("#width_to").val());
			$("#slider_width").slider( "values" , 1 , value );
		}).unbind('mousemove.spinbox').unbind('mouseout.spinbox').unbind('mousedown.spinbox').unbind('mouseup.spinbox');	

	
	
	
	/*------------------------------------enable-filter----------------------------------------------*/
	var elements=$('#wares_items li');
	
	$('#filter_form').submit(function(){
		var price_min=parseInt($("#price_from").val());
		var price_max=parseInt($("#price_to").val());
		
		var width_min=parseInt($("#width_from").val());
		var width_max=parseInt($("#width_to").val());
		
		var length_min=parseInt($("#length_from").val());
		var length_max=parseInt($("#length_to").val());
		
		elements.each(function(){
							var price=Number($(this).find('.price').html().replace(/\D/g,''));	
							var length=parseInt($(this).find('i.gab_length').html().replace(/\D/g,''));
							var width=parseInt($(this).find('i.gab_width').html().replace(/\D/g,''));
							if(price>=price_min&&price<=price_max&&length>=length_min&&length<=length_max&&width>=width_min&&width<=width_max){
								$(this).show();
							}else{
								$(this).hide();
							}
						});
		return false;
	});
	
	
	$('#filter_type li').click(function(){
		if(!$(this).hasClass('active')){
			$('#filter_type li').removeClass('active');
			$(this).addClass('active');
				var type=$(this).find('a').attr('rel');
			if(type=='filter'){
				$('#filter_form').submit();
				$('#catalog_filter_content').show();
				$('#filter_form').slideDown();
				
			}
			if(type=='all'){
				$('#catalog_filter_content').hide();
				$('#filter_form').slideUp();
				elements.show();
			}
		}
		return false;
		
	});
	
	
	
	
});